<!-- 商城主页面 -->
<template>
	<view class="container">
		<uni-nav-bar statusBar="true"  v-if="tabCurrent==1||tabCurrent==2" fixed="true" :title="title"></uni-nav-bar>
		<Index :scrollTop="scrollTop"  :style="tabCurrent == 0?'':'display:none'" ref="mainindex"></Index>
		<Cate  :style="tabCurrent == 1?'':'display:none'"></Cate>
		<Cart v-if="tabCurrent == 2"></Cart>
		<My ref="my" v-show="tabCurrent == 3"></My>
		<newTabbar :color="tabbarColor" :scan="false" @current="current" :act="tabCurrent" :list="tabbarList"></newTabbar>
	</view>
</template>

<script>
	import { getCategory } from '@/api/mall.js'
	import Index from "@/mall/index/index.vue"
	import Cate from "@/mall/cate/cate.vue"
	import Cart from "@/mall/cart/cart.vue"
	import My from "@/mall/my/my.vue"
	import newTabbar from "@/components/new-tabbar/new-tabbar.vue"
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	import wechat from '@/common/wechat.js'
	export default {
		components: {
			Index,
			Cate,
			My,
			Cart,
			newTabbar,
			uniNavBar
		},
		data() {
			return {
				scrollTop: 0,
				tabbarColor: "#FB3737",
				title: "",
				tabCurrent: 0,
				tabbarList: [{
					name: "首页",
					iconPath: "/static/images/tabar/home2.png",
					selectIconPath: "/mall/static/images/tabbar/1.png"
				}, {
					name: "分类",
					iconPath: "/static/images/tabar/category2.png",
					selectIconPath: "/mall/static/images/tabbar/2.png"
				}, {
					name: "购物车",
					iconPath: "/mall/static/images/tabbar/5.png",
					selectIconPath: "/mall/static/images/tabbar/3.png"
				}, {
					name: "我的",
					iconPath: "/static/images/tabar/user2.png",
					selectIconPath: "/mall/static/images/tabbar/4.png"
				}]
			};
		},
		onLoad(option) {
			if(option.current) {
				this.tabCurrent = Number(option.current)
			}
			if (!uni.getStorageSync("Authori-zation")) {
				if (option.scene) {
					let options = utils.urlDecode(option)
					uni.setStorageSync("pid", options.uid) //统一改成uid
					uni.setStorageSync("pos", options.uk)
					uni.navigateTo({
						url: `/pages/login/login`
					})
				}
			}
			// #ifdef H5
			if (!uni.getStorageSync("Authori-zation")) {
					wechat.share(uni.getStorageSync("share")[2].title, "", window.location.href, uni.getStorageSync("share")[2].url)
			} else {
					wechat.share(uni.getStorageSync("share")[2].title, "", window.location.href + '?uid=' + uni.getStorageSync("userInfo").uid + "&uk=1", uni.getStorageSync("share")[2].url)
			}
			// #endif
		},
		onShow() {
			if (this.tabCurrent == 2) {
				this.tabCurrent = 10;
				this.$nextTick(() => {
					this.tabCurrent = 2;
					this.title = '购物车'
				})
			}
			if (this.tabCurrent == 3) {
				this.$refs.my.getUserInfo()
			}
		},
		onShareAppMessage() { //分享
			if (!uni.getStorageSync("Authori-zation")) {
				return {
					title: uni.getStorageSync("share")[2].title,
					path: '/mall/index/indexPage',
					imageUrl: uni.getStorageSync("share")[2].url
				}
			} else {
				return {
					title: uni.getStorageSync("share")[2].title,
					path: '/mall/index/indexPage?uid=' + uni.getStorageSync("userInfo").uid + "&uk=1",
					imageUrl: uni.getStorageSync("share")[2].url
				}
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		onReachBottom() {
			if (this.tabCurrent == 0) {
				this.$refs.mainindex.lower();
			}
		},
		methods: {
			current(e) {
				this.title = e.title
				this.tabCurrent = e.current
				if(this.tabCurrent == 3) {
					this.$refs.my.getUserInfo()
				}
			}
		}
	};
</script>

<style>
	page{
		
		background-color:#f6f6f6!important;
	}
</style>
